import {reqGoods} from "../../request/api"
//初始值
const initState = {
   //商品分类列表
   CateList:[]
}

//actionTypes
const types = {
    //修改 
    CHANGE_CATE_LIST:"HOME_CHANGE_CATE_LIST"


}

//reducer 修改数据
const reducer = (state = initState, action) => {
    switch (action.type) {
        case types.CHANGE_CATE_LIST:
            return {
                ...state,
                CateList:action.arr
            }
        default:
            return state;
    }

}

//actionCreators组件派发任务
export const actions = {
    //修改，请求
     //
    // 分类商品
    changeCateList:arr=>({type:types.CHANGE_CATE_LIST,arr}),
    reqGoods:id=>(dispatch,getState)=>{
        reqGoods({fid:id}).then(res=>{
            if(res.data.code===200){
                dispatch(actions.changeCateList(res.data.list))
                // console.log(getState());
            }
        })
    }
}

//selectors 导出数据

export const getCateList= state =>state.cate.CateList

export default reducer